Using Qcard DLL - Lesson 1

by Alyce Watson

Home

A Contest!

Fast Bitmaps

Button Lesson

API Corner

Listbox Trivia

Listbox Demo 1

Listbox Demo 2

SpriteByte-Shooting

Qcard DLL-Lesson 1

DDOC Print Demo

Newsletter help

Index


This is the first in a series of lessons on the use of the QCard32.DLL.

Where to Find QCard32.DLL

This series of lessons uses the Qcard32.dll, a freeware library of playing card images. It is written by Stephen Murphy. Qcard32.DLL website: [http://www.telusplanet.net/public/stevem/] You can also obtain a copy of the DLL in issue #120 of the Liberty BASIC Newsletter.

What is in QCard32.DLL?

The DLL includes card face images for all suits and number values, from Ace to King, with hearts, spades, diamonds and clubs. There is a choice of six card backs. There are also jokers. It doesn't just provide images, though. It provides a way to manage the cards.

Getting Started with QCard

The first thing that must be done is to initialize the deck. This is done with a call to InitializeDeck:

    open "qcard32.dll" for dll as #qc
    calldll #qc, "InitializeDeck",_
    hWnd as long,_    'window or graphicbox handle
    r as long         'returns 0 on success

The DLL includes two decks of cards. The first deck has indices of 1-52, and the second deck has indices of 53-104. The cards are best displayed with the DealCard function:

    calldll #qc, "DealCard",_
    hWnd as long,_    'window or grahicbox handle
    nC as long,_      'index of desired card
    x as long,_       'x location on window
    y as long,_       'y location on window
    r as void

The DLL comes with a very good help file. It says this about DealCard:

It updates the card's X and Y properties to the location you deal the card. Most importantly, it grabs from the video display that portion of the screen your card will be covering over. That is, it keeps a copy of the image which lies behind that card.

By default, the cards are displayed face up. The desired status (face up, or face down) is set with the SetCardStatus function, which is as follows:

    calldll #qc, "SetCardStatus",_ 
    nC as long,_    'index of card
    face as long,_  'desired face - 1=front or 0=back
    r as void

DEMO

The following demo shows the first deck of cards dealt face up in a row. The second deck is dealt face down. Some card sound wavs are included with this newsletter. You will also need the qcard32.dll, which is available in the places mentioned at the top of this article.

[varSetup]
i=0         'i will be our counter var in for/next loops

'start with the basics and open a window containing a graphicbox
nomainwin
    WindowWidth=640:WindowHeight=480
    UpperLeftX=1:UpperLeftY=1

    menu #1, "&File", "E&xit", [quit]
    graphicbox #1.g, 0, 0, 640, 440
    open "Card Game" for window_nf as #1
    #1 "trapclose [quit]"

    'get graphicbox handle
    hBox=hwnd(#1.g)

    'open the dll
    open "qcard32.dll" for dll as #qc
    'initialize the deck
    Call InitializeDeck hBox

    'draw a nice background
    #1.g "down; fill 10 190 225"

    playwave "shuffle.wav",sync

    'the DLL allows for two decks
    'the first deck includes cards 1 - 52
    'by default, cards are face up
    'deal first deck face up
    for i = 1 to 52
        'window handle, card index number, x, y
        Call DealCard hBox,i,i*12,10
        playwave "card.wav",sync
        'pause 100 milliseconds between cards
        call Pause 100
    next

    playwave "shuffle.wav",sync

    'cards 53 to 104 are in the second deck
    'deal second deck face down
    'set status of all cards to 0, which is face down
    for i = 53 to 104
        call SetCardStatus i, 0
        Call DealCard hBox,i,(i-52)*6,67+i
        playwave "card.wav",sync
        'pause 100 milliseconds between cards
        call Pause 100
    next
wait

[quit] close #qc:close #1:end

''''''''''''''''''''
'subs and functions:

Sub Pause ms
    'pause ms number of milliseconds
    calldll #kernel32,"Sleep",_
    ms as long, re as void
    End Sub

Sub InitializeDeck hndle
    calldll #qc, "InitializeDeck",_
    hndle as long,r as long
    End Sub

Sub DealCard hndle,nC,x,y
    'places card on window whose handle is hndle at x,y
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    calldll #qc, "DealCard",hndle as long,nC as long,_
    x as long,y as long,r as void
    End Sub


Sub SetCardStatus nC,face
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    'face:  0=facedown,1=faceup
    calldll #qc, "SetCardStatus",nC as long,_
    face as long,r as void
    End Sub

Home

A Contest!

Fast Bitmaps

Button Lesson

API Corner

Listbox Trivia

Listbox Demo 1

Listbox Demo 2

SpriteByte-Shooting

Qcard DLL-Lesson 1

DDOC Print Demo

Newsletter help

Index